<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('课程列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <div class="card card-primary card-outline card-outline-tabs mb-0">
        <div class="card-body">
            <form id="formId" class="form-inline">
                <input class="form-control mr-1" placeholder="课程名称" type="text" name="courseName"/>
                <a class="btn btn-primary btn-rounded mr-1" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                <a class="btn btn-warning btn-rounded" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </form>
        </div>
    </div>
    <div class="select-table table-striped">
        <table id="bootstrap-table" class="table-striped"></table>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var prefix = "/course";
    var channelId =  [[${channelId}]];
    var courseId =  [[${courseId}]];
    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/package/select/list.json?courseId="+courseId+"&channelId="+channelId,
            modalName: "课程",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'courseId',
                    title: 'id'
                },
                {
                    field: 'courseName',
                    title: '名称'
                },
                {
                    field: 'addTime',
                    title: '创建时间'
                },
                {
                    field: 'sourcePrice',
                    align: 'center',
                    title: '原价'
                },
                {
                    field: 'price',
                    align: 'center',
                    title: '优惠价'
                },
                {
                    field: 'lessonNum',
                    align: 'center',
                    title: '课时'
                }]
        };
        $.table.init(options);
    });

    function submitHandler() {
        table.set();
        var rowss = $('#bootstrap-table').bootstrapTable('getSelections');//行的数据
        if (rowss.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var courseIds = "";
        for(var i=0;i<rowss.length;i++){
            courseIds += rowss[i].courseId+",";
        }
        courseIds = courseIds.substring(0, courseIds.lastIndexOf(','));
        $.post(prefix+"/package/save.json",{courseId:courseId,courseIds:courseIds},function(json){
            $.modal.msgSuccess("添加成功！");
            setTimeout(function () {
                window.parent.RefreshTable();
                window.parent.layer.closeAll();
            }, 1200);
        });
    }
</script>
</body>
</html>